package nxu.service;

import nxu.dao.DbHelper;
import nxu.entity.Post;
import nxu.entity.comment;

import java.util.List;

public class CommentService {
    public boolean addComment(comment com){
        boolean success=false;

        try {

        String addCommentSql="insert into comment (content,uid,pid) values(:content,:uid,:pid)";
        DbHelper.JDBI.withHandle(handle -> handle.createUpdate(addCommentSql)
                .bind("content",com.getContent())
                .bind("uid",com.getUid())
                .bind("pid",com.getPid())
                .execute()
        );
        success=true;
        }catch (Exception e){
            System.out.println("error");
        }
        System.out.println("add");
        return success;
    }

    public List<comment> showComment( String pid){
        String showCommentSql = "select * from comment where pid=?";
        return DbHelper.JDBI.withHandle(handle -> handle.createQuery(showCommentSql)
                .bind(0,pid)
                .mapToBean(comment.class)
                .list()
        );



    }

}
